<?php
!defined('LZ_MODULE') && die('Access Denied');
$m = $_GET['m'];
include_once('model/guestbook.php');
$obj = new LZ_Guestbook;


if ($m == 'new')
{
	if (!$_SESSION['login_user'])
	{
		die("what do you want to do?");
	}
	$data = filter_array($_POST,'name!,email,htmlspecialchars:content!');
	if ($data)
	{
		$data['user_id'] = $_SESSION['login_user']['user_id'];
		$data['date'] = time();
		echo ($obj->add($data))?'success':'error';
	}
	else 
		echo FILL_ALL;
	die;	
}


$total = $obj->get_list( array('select' => 'count(*)','replied'=>true,'user_id'=>$_SESSION['login_user']['user_id']));
$total = $total[0]['count(*)'];
$page = intval($_GET['page']);
$per_page = (intval($config['guestbook_per_page_front']))?intval($config['guestbook_per_page_front']):10;
!$page && $page=1;
$total_page = ceil($total/$per_page);
!$total_page && $total_page=1;
$page>$total_page && $page = $total_page;
$items = $obj->get_list( array('from' => ($page-1)*$per_page,'total'=>$per_page,'replied'=>true,'user_id'=>$_SESSION['login_user']['user_id']));

$pager = PAGER_TOTAL.$total.GB_PAGER_ITEMS.' ';
$total_page > 1 && $pager.= $total_page.PAGER_PAGE;
$pager.= '<br />';
$pager.= html_pager("?p=guestbook",$total_page,$page);
$view_data['pager'] = $pager;



$view_data['items'] = $items;
$view_data['page_description'] = GUESTBOOK;
$view_data['title'] = GUESTBOOK;
$view_data['page_description'] = GUESTBOOK;
$view_data['site_keywords'] = GUESTBOOK;
include_once('controller/left.php');

?>